主题
删除注册表键 - RegistryDeleteKey
函数简介
删除指定的注册表键,支持递归删除子键。
接口名称
RegistryDeleteKeyDLL调用
cpp
int32_t RegistryDeleteKey(int64_t instance, int32_t rootKey, const char* subKey, int32_t recursive);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| rootKey | 整数型 | 根键类型:0 HKEY_CLASSES_ROOT、1 HKEY_CURRENT_USER、2 HKEY_LOCAL_MACHINE、3 HKEY_USERS、4 HKEY_CURRENT_CONFIG。 |
| subKey | 字符串 | 子键路径。 |
| recursive | 整数型 | 是否递归删除子键。1 递归删除所有子键,0 仅删除当前键(当前键必须没有子键)。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int ret = ola.RegistryDeleteKey(1, "Software\\OLAPlug\\Temp", 1);csharp
using OLAPlug;
var ola = new OLAPlugServer();
int ret = ola.RegistryDeleteKey(1, @"Software\OLAPlug\Temp", 1);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
ret = ola.RegistryDeleteKey(1, r"Software\OLAPlug\Temp", 1)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
int ret = ola.RegistryDeleteKey(1, "Software\\OLAPlug\\Temp", 1);go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
ret := ola.RegistryDeleteKey(1, "Software\\OLAPlug\\Temp", 1)rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let ret = ola.registry_delete_key(1, "Software\\OLAPlug\\Temp", 1);cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.RegistryDeleteKey(1, "Software\\OLAPlug\\Temp", 1)vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.RegistryDeleteKey(1, "Software\OLAPlug\Temp", 1)text
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.RegistryDeleteKey (1, “Software\\OLAPlug\\Temp“, 1)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.RegistryDeleteKey(1, "Software\\OLAPlug\\Temp", 1);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.RegistryDeleteKey(1, "Software\\OLAPlug\\Temp", 1)cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int32_t ret = ola.RegistryDeleteKey(1, "Software\\OLAPlug\\Temp", 1);原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
RegistryDeleteKey(instance, 1, "Software\\OLAPlug\\Temp", 1);csharp
using System.Runtime.InteropServices;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
long instance = CreateCOLAPlugInterFace();
RegistryDeleteKey(instance, 1, @"Software\OLAPlug\Temp", 1);python
from ctypes import CDLL, c_int, c_int64
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.RegistryDeleteKey(instance, 1, b"Software\\OLAPlug\\Temp", 1)返回值
| 返回值 | 说明 |
|---|---|
1 | 成功。 |
0 | 失败。 |
注意事项
| 项目 | 说明 |
|---|---|
| 删除行为 | 删除操作不可逆,建议在删除前使用 RegistryBackupToFile 进行备份。 |
| 递归删除会删除所有子键和值 | 递归删除会删除所有子键和值,使用时务必谨慎。 |
| 管理员权限 | 删除 HKEY_LOCAL_MACHINE 下的键可能需要管理员权限。 |
| 如果键正在被其他程序使用 | 如果键正在被其他程序使用,删除可能失败。 |
